package javaPersistence;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import beans.VentaServicioBean;

public class SaleService {
	
	public boolean insertSaleService(int idUsuario, String idCliente, int idServicio, double cantidadServ){
		try {
			DBConexConSoft dbConSoft = DBConexConSoft.getInstance();
			StringBuilder query = new StringBuilder("INSERT INTO VENTASERVICIO (idUsuario, idCliente,idServicio,cantidadServ) VALUES (");
			query.append(idUsuario).append(",'").append(idCliente).append("',").append(idServicio).append(",").append(cantidadServ).append(")");
			System.out.println("query: "+query.toString());
			if(dbConSoft.getDeclaracion().executeUpdate(query.toString()) > 0)
				return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public ArrayList<VentaServicioBean> loadAllDataSalesServices(){
		ArrayList<VentaServicioBean> arrSaleService = new ArrayList<VentaServicioBean>();
		try {
			VentaServicioBean saleServiceB;
			DBConexConSoft dbConSoft = DBConexConSoft.getInstance();
			StringBuilder query = new StringBuilder();
			query.append("SELECT * FROM SALESSERVICES");
			System.out.println("query: "+query.toString());
			ResultSet resultSet = dbConSoft.getDeclaracion().executeQuery(query.toString());
			while (resultSet.next()) {
				saleServiceB = new VentaServicioBean();
				saleServiceB.setIdventaServicio(resultSet.getInt(1));
				saleServiceB.setIdUsuario(resultSet.getInt(2));
				saleServiceB.setNombreUsuario(resultSet.getString(3));
				saleServiceB.setIdCliente(resultSet.getString(4));
				saleServiceB.setNombreCliente(resultSet.getString(5));
				saleServiceB.setIdServicio(resultSet.getInt(6));
				saleServiceB.setNombreServicio(resultSet.getString(7));
				saleServiceB.setCantidadServ(resultSet.getDouble(8));
				saleServiceB.setPrecioServ(resultSet.getDouble(9));
				saleServiceB.setTotalServ(resultSet.getDouble(10));
				arrSaleService.add(saleServiceB);
			}
		} catch (SQLException e) {
		}
		return arrSaleService;
	}

}
